home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / process.test < prev    next >
Encoding:
Text File  |  1992-11-07  |  3.1 KB  |  114 lines

  1. #
  2. # process.test
  3. #
  4. # Tests for the fork, execl and  wait commands.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: process.test,v 2.0 1992/10/16 04:50:05 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. # Proc to fork and exec child that loops until it gets a signal.
  22.  
  23. proc ForkLoopingChild {{setPGroup 0}} {
  24.     flush stdout
  25.     flush stderr
  26.     set newPid [fork]
  27.     if {$newPid != 0} {
  28.         return $newPid
  29.     }
  30.     if $setPGroup {
  31.         id process group set
  32.     }
  33.     execl ../tcl {-qc {catch {while {1} {sleep 1}}; exit 10}}
  34.     error "Should never make it here"
  35. }
  36.  
  37.  
  38. # Test fork, execl, and wait commands.
  39.  
  40. Test process-1.1 {fork, execl, wait tests} {
  41.     set newPid [fork]
  42.     if {$newPid == 0} {
  43.         execl ../tcl {-qc {sleep 1;exit 12}}
  44.         error "Should never make it here"
  45.     }
  46.     lrange [wait $newPid] 1 end
  47. } 0 {EXIT 12}
  48.  
  49. Test process-1.2 {fork, execl, wait tests} {
  50.     set newPid [ForkLoopingChild]
  51.     sleep 1
  52.  
  53.     kill $newPid
  54.     lrange [wait $newPid] 1 end
  55. } 0 {SIG SIGTERM}
  56.  
  57. set newPid1 [ForkLoopingChild]
  58. set newPid2 [ForkLoopingChild]
  59.  
  60. Test process-1.3 {fork, execl, wait tests} {
  61.     sleep 3 ;# Give em a chance to get going.
  62.  
  63.     kill [list $newPid1 $newPid2]
  64.  
  65.     list [wait $newPid1] [wait $newPid2]
  66.  
  67. } 0 [list "$newPid1 SIG SIGTERM" "$newPid2 SIG SIGTERM"]
  68.  
  69. Test process-1.4 {fork, execl, wait tests} {
  70.     fork foo
  71. } 1 {wrong # args: fork}
  72.  
  73. Test process-1.5 {fork, execl, wait tests} {
  74.     wait baz
  75. } 1 {expected integer but got "baz"}
  76.  
  77. Test process-1.6 {fork, execl, wait tests} {
  78.     set testPid [ForkLoopingChild]
  79.     kill $testPid
  80.     set result [wait $testPid]
  81.     lrange $result 1 end
  82. } 0 {SIG SIGTERM}
  83.  
  84. # Test extended wait functionality, if available.
  85.  
  86. catch {wait -nohang 1} result
  87. if {$result == "wrong # args: wait pid"} return
  88.  
  89. Test process-2.1 {fork, execl, wait tests} {
  90.     set testPid [ForkLoopingChild]
  91.     set result1 [wait -nohang $testPid]
  92.     kill $testPid
  93.     set result2 [wait $testPid]
  94.     list $result1 [lrange $result2 1 end]
  95. } 0 {{} {SIG SIGTERM}}
  96.  
  97. Test process-2.2 {fork, execl, wait tests} {
  98.     set testPid [ForkLoopingChild 1]
  99.     set result1 [wait -nohang -pgroup $testPid]
  100.     kill $testPid
  101.     set result2 [wait -pgroup $testPid]
  102.     list $result1 [lrange $result2 1 end]
  103. } 0 {{} {SIG SIGTERM}}
  104.  
  105. Test process-2.3 {fork, execl, wait tests} {
  106.     set testPid [ForkLoopingChild]
  107.     set result1 [wait -nohang -pgroup -untraced $testPid]
  108.     kill $testPid
  109.     set result2 [wait -pgroup -untraced $testPid]
  110.     list $result1 [lrange $result2 1 end]
  111. } 0 {{} {SIG SIGTERM}}
  112.  
  113.  
  114.